package com.WebController;

import java.io.IOException;

import javax.annotation.Resource;

import org.apache.commons.io.FilenameUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;

@Controller
public class FastDFSController {
	
	//fastdfs 上传文件对象
	@Resource
	private FastFileStorageClient fdfs;
	
	
	@RequestMapping("/Show")
	public String Show() {
		return "u";
	}
	
	//文件上传
	@RequestMapping("/FastDFS_upload")
	@ResponseBody
	public String FastDFS_upload(MultipartFile file) throws IOException {
		//  file  前台传过来要上传的文件
		//1.文件输入流,2.文件大小,文件扩展名,4.null
		StorePath path = fdfs.uploadFile(file.getInputStream(), file.getSize(), FilenameUtils.getExtension(file.getOriginalFilename()), null);
		return path.getFullPath();
	}
	
	//删除文件
	@RequestMapping("/FastDFS_delete")
	@ResponseBody
	public String FastDFS_delete() {
		//删除文件（里面的参数是文件的路径）
		fdfs.deleteFile("group1/M00/00/00/wKgZjlsCgz-AV_MXAAAeQEu8ftc288.jpg"); 
		return "删除成功";
	}
	
	
	
	
}


